home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5466 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  70 lines

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: int main() vs int main(void)
  5. Date: 8 Feb 96 20:19:07 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.823810747@rscernix>
  8. References: <1996Feb7.201848.18734@atlas.tntech.edu> <4fde76$flj@sam.inforamp.net>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4fde76$flj@sam.inforamp.net> rmorin@inforamp.net (Randy Charles Morin) writes:
  13.  
  14. >My understanding is that in C++, there is absolutely no difference.  But in C, 
  15. >there is a slight difference.  I think the proper example is the following...
  16. >
  17. >void f(void);
  18. >void f(){};
  19. >
  20. >This two line program is the key. 
  21.  
  22. This is by no means a C program.  Why?
  23.  
  24. >It compile in C++ and doesn't in C.
  25.  
  26. The only reason it may not compile in C is because it contains an empty
  27. declaration (can you see it?).
  28.  
  29. Otherwise it is a legal C translation unit and it does compile (after
  30. removing the empty declaration):
  31.  
  32.     ues5:~/tmp 25> cat test.c
  33.     void f(void);
  34.     void f(){}
  35.     ues5:~/tmp 26> cc -c test.c
  36.     ues5:~/tmp 27> c89 -c test.c
  37.     ues5:~/tmp 28> gcc -pedantic -c test.c
  38.     ues5:~/tmp 29> 
  39.  
  40. >You have to change the program to...
  41. >
  42. >void f(void);
  43. >void f(void){};
  44. >
  45. >..for it to compile in C.  
  46.  
  47. This one is just as broken as the first one and just as correct after
  48. the empty declaration is removed.
  49.  
  50. >But, I'm not an expert on the subject.
  51.  
  52. A very good reason to keep your mouth shut, in order to avoid confusing 
  53. other people with your misconceptions.
  54.  
  55. >So, I'd confirm this by compiling the programs yourself.
  56.  
  57. It's better to search the confirmation in books, not in compilers.
  58.  
  59. >No other differences exist in my books.
  60.  
  61. If there is any difference between your examples in your books, then those
  62. books are not about the C programming language.
  63.  
  64. Dan
  65. --
  66. Dan Pop
  67. CERN, CN Division
  68. Email: danpop@mail.cern.ch 
  69. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  70.